import pymysql

# 2、创建数据库链接
connect = pymysql.connect(host="master", port=3306, user="root", password="123456", database="bigdata")

# 3、获取游标，用于执行sql
cursor = connect.cursor()

# 执行sql查询数据
cursor.execute("""
    select
    city,
    count(1) as flow 
    from
    cars
    group by city
""")

# 获取数据
data = cursor.fetchall()

for city,flow in data:
    print(city,flow)

# 关闭链接
connect.close()
